package com.acme.bankapp.service.bank;

import com.acme.bankapp.domain.bank.Account;
import com.acme.bankapp.domain.bank.Bank;
import com.acme.bankapp.domain.bank.Client;

import java.util.ArrayList;
import java.util.List;

/**
 * Class representing service methods to work with bank
 */
public class BankService {
    private BankService(){
    }
    /**
     * Adds client to bank
     * @param bank Bank
     * @param client Client to ba added
     */
    public static void addClient(Bank bank, Client client){
        bank.addClient(client);
    }

    /**
     * Returns collection of all accounts for specified bank
     * @param bank Bank to get accounts from
     * @return collection of all bank accounts
     */
    public static List<Account> getAllAccounts(Bank bank){
        List<Account> result = new ArrayList<Account>();
        for(Client c:bank.getAllClients()){
           if(c.getAccount()!=null){
                result.add(c.getAccount());
            }
        }
        return result;
    }

}
